﻿using System.ComponentModel;
using System.Diagnostics;
using System.Xml.Serialization;

using Microsoft.WowAddonStudio.Lua.Parser;

namespace Microsoft.WowAddonStudio.Lua.Model
{
    /// <summary>
    /// A Lua declaration.
    /// </summary>
    [DebuggerDisplay("Name = {Name}, Type = {Type}")]
    public class Declaration : Element
    {
        private QualifiedName qualifiedName;

        /// <summary>
        /// Gets or sets the type of the declaration.
        /// </summary>
        [XmlAttribute("type")]
        [DefaultValue(LuaType.Unknown)]
        public virtual LuaType Type { get; set; }

        /// <summary>
        /// Gets or sets the uri of the file that is the source of the declaration.
        /// </summary>
        [XmlIgnore]
        public string SourceUri { get; set; }

        /// <summary>
        /// Gets or sets the location of the declaration.
        /// </summary>
        [XmlIgnore]
        public LexLocation Location { get; set; }
        
        /// <summary>
        /// Gets or sets the qualified name of the declaration. Can be null.
        /// </summary>
        [XmlIgnore]
        public QualifiedName QualifiedName
        {
            get { return qualifiedName; }
            set
            {
                qualifiedName = value;
                this.Name = qualifiedName.UnqualifiedIdentifier.Name;
            }
        }

        /// <summary>
        /// Gets a value indicating whether the declaration is qualified.
        /// </summary>
        [XmlIgnore]
        public bool IsQualified
        {
            get { return this.QualifiedName != null && this.QualifiedName.IsQualified; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether the declaration is local.
        /// </summary>
        [XmlIgnore]
        public bool IsLocal { get; set; }
    }
}
